/******************************************************************************
*
* This file is part of FreeTrack (http://code.google.com/p/qtfreetrack).
* BY Willy Gardiol (willy@gardiol.org)
*
* FreeTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/

#include "rotatingwidget.h"

//QList<RotatingWidget*> RotatingWidget::list_members;

RotatingWidget::RotatingWidget(QWidget* parent) :
    FTBasicWidget(parent)
{
}

RotatingWidget::~RotatingWidget()
{
}

//void RotatingWidget::checkOrientation(FTControls::Orientation new_orientation)
void RotatingWidget::resizeEvent(QResizeEvent *)
{
    int w = width();
    int h = height();
    if ( w >= h )
        setOrientation( FTControls::horizontal );
    else
        setOrientation( FTControls::vertical );
}


void RotatingWidget::setOrientation(FTControls::Orientation new_orientation)
{
    if ( _orientation == new_orientation )
        return;

    QLayout* new_layout = 0;


    // Get new layout
    switch ( new_orientation )
    {
    case FTControls::vertical:
        new_layout =  createVertical();
        break;
    case FTControls::horizontal:
        new_layout = createHorizontal();
        break;
    default:
        new_layout = 0;
    }
    // If we have a new layout...
    if ( new_layout != 0 )
    {   // Delete old layout first (required by Qt)
        if ( layout() != 0 )
            delete layout();
        // then set the new layout.
        new_layout->setSpacing(0);
        new_layout->setContentsMargins( 0,0,0,0 );
        setLayout( new_layout );
        new_layout->invalidate();
        new_layout->activate();
        new_layout->update();
    }
    _orientation = new_orientation;
}

QLayout* RotatingWidget::createHorizontal()
{
    return createVertical();
}

QLayout* RotatingWidget::createVertical()
{
    return 0;
}
